<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>项目进度开票管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				title:"项目结算开票管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xmFinance/listPageXMInvoice?invoice_type=1&no_receive=1',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				]],
				columns:[[
					{title:'创建时间',field:'create_time',width:150,align:'center'},
					{title:'部门',field:'dept_name',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:100,align:'center'},
					//{title:'票据抬头',field:'invoice_title',width:100,align:'center'},
					{title:'收款预警日期',field:'alarm_time',width:100,align:'center'},
					{title:'开票额',field:'account_receivable',width:100,align:'center'},
					{title:'已收额',field:'has_receivable',width:100,align:'center'},
					{title:'未收额',field:'not_receivable',width:100,align:'center',formatter:function(value,row,index){
						return row.account_receivable-row.has_receivable-row.warranty_value;
					}},
					{title:'质保金预警日期',field:'warranty_alarm_time',width:100,align:'center'},
					{title:'质保金',field:'warranty_value',width:100,align:'center'},
					{title:'已收质保金',field:'already_receive',width:100,align:'center'},
					{title:'未收质保金',field:'warranty_left',width:100,align:'center',formatter:function(value,row,index){
						return row.warranty_value-row.already_receive;
					}},
					//{title:'摘要',field:'remark',width:150,align:'center'},
					{title:'审核状态',field:'status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "审核中";
						}else if(value==2){
							return "审核不通过";
						}else if(value==3){
							return "审核通过";
						}
						return "未提交审核";
					}},
					{title:'结算收款',field:'more',width:80,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(rowData.status == 3){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-transfer' title='结算收款' onclick=\"javascript:viewInMoneyData('"+rowData.xm_id+"','"+rowData.xm_code+"','"+rowData.xm_name+"','"+rowData.invoice_title+"','"+rowData.id+"','"+rowData.account_receivable+"','"+rowData.has_receivable+"','"+rowData.warranty_value+"','"+rowData.already_receive+"');\"/>";
						}
						else
						{
	                    	str+="无";
						}
	                    return str;
					}},
					{title:'质保金收款',field:'warranty_more',width:80,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(rowData.status == 3){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-pur_payment2' title='质保金收款' onclick=\"javascript:viewWarrantyData('"+rowData.xm_id+"','"+rowData.xm_code+"','"+rowData.xm_name+"','"+rowData.invoice_title+"','"+rowData.id+"','"+rowData.warranty_value+"','"+rowData.already_receive+"');\"/>";
						}
						else
						{
	                    	str+="无";
						}
	                    return str;
					}},
					{title:'详情操作',field:'opMore',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(rowData.status == 0){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editXMInvoice('"+rowData.id+"');\"/> &nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/> &nbsp;";
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteData('"+rowData.id+"');\"/>";
						}
						if(rowData.status == 2){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editXMInvoice('"+rowData.id+"');\"/> &nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/> &nbsp;";
						}
						if(rowData.status == 1 || rowData.status == 3){
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.XM_INVOICE_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;";
	                    	str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:viewData('"+rowData.id+"');\"/>";
						}
	                    return str;
					}}
				]],
				
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
        function  viewInMoneyData(xm_id,xm_code,xm_name,invoice_title,invoiceId,account_receivable,has_receivable,warranty_value,already_receive){
        	var end_finish = 0;
        	if((parseFloat(warranty_value) == parseFloat(already_receive)&&parseFloat(warranty_value) !=0)&&(parseFloat(account_receivable) == parseFloat(has_receivable)+parseFloat(warranty_value))){
        		end_finish = 1;
        	}
        	var param = "end_finish="+end_finish+"&xm_id="+xm_id+"&xm_code="+encodeURIComponent(xm_code)+"&xm_name="+encodeURIComponent(xm_name)+"&invoice_title="+encodeURIComponent(invoice_title)+"&invoice_id="+invoiceId+"&account_receivable="+account_receivable+"&has_receivable="+has_receivable+"&warranty_value="+warranty_value;
			openDialogResize("<%=contextPath %>/springViews/xm/xmInMoneyEnd.jsp?"+param,1000, 800);
		}
		
        function  viewWarrantyData(xm_id,xm_code,xm_name,invoice_title,invoice_id,warranty_value,already_receive){
        	var end_finish = 0;
        	if(parseFloat(warranty_value) == parseFloat(already_receive)){
        		end_finish = 1;
        	}
        	var param = "end_finish="+end_finish+"&xm_id="+xm_id+"&xm_code="+encodeURIComponent(xm_code)+"&xm_name="+encodeURIComponent(xm_name)+"&invoice_title="+encodeURIComponent(invoice_title)+"&invoice_id="+invoice_id+"&warranty_value="+warranty_value+"&already_receive="+already_receive;
			openDialogResize("<%=contextPath %>/springViews/xm/xmWarrantyInMoneyEnd.jsp?"+param,1000, 800);
		}
        function addInvoice(){
        	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditEndInvoice.jsp?callback=rtCallBack&invoice_type=1",1000, 800);
        }
		function shenpi(obj,id){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditEndInvoice.jsp?id="+id+"&isShow=1";
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_INVOICE_SHENPI%>")+"&businessId="+id;
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
	       
	    } 
		
		function deleteData(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xmFinance/deleteInvoice",
						data:"id="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}

		function  editXMInvoice(id){
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditEndInvoice.jsp?invoice_type=1&id="+id+"&callback=rtCallBack",1000, 800);
	
		}
		function  viewData(id){
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditEndInvoice.jsp?invoice_type=1&id="+id+"&isShow=1",1000, 800);
		}

		function rtCallBack(){
			$('#table').datagrid('reload');
		}

		function doSearch()
		{
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			var searchValue = $('#searchValue').val();
			var dept_id = $("#dept_id").combotree('getValue');
			$('#table').datagrid('load',{
				invoice_type:0,
				searchValue:searchValue,
				start_time:start_time,
				dept_id : dept_id,
				end_time:end_time
				
			});
		}
	</script>
		<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addInvoice(0);">新增结算开票</a>
			</div>
			<div align="right">
				所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; 
				开始时间：<input id="start_time" name="start_time" class="easyui-datebox" style="width:100px;"/>&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" style="width:100px;"/>
				项目编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="项目编号/名称" placeholder="项目编号/名称 "  />&nbsp;&nbsp; 
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>